package com.example.blue;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Locale;

public class DuizhiResActivity extends AppCompatActivity {
    public Integer predictLabel;
    public Integer predictScore;
    public String[] displayNames;
    public double[] displayFea;

    private TextView textView1;
    private TextView textView2;
    private TextView textView3;
    private TextView textView4;
    private TextView textView5;
    private TextView textView6;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_duizhi_res);
        // 开启返回箭头
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(null);
        getSupportActionBar().setTitle("对指测试结果");


        Intent intent = getIntent();
        predictLabel = intent.getIntExtra("predictLabel",100);
        predictScore= intent.getIntExtra("predictScore",100);
        displayNames = intent.getStringArrayExtra("displayNames");
        displayFea=intent.getDoubleArrayExtra("displayFea");
        System.out.println("DuizhiResult----"+displayFea[0]+" "+displayFea[1]+" "+displayFea[2]+" "+displayFea[3]);
        textView1=findViewById(R.id.jiaosudu);
        textView2=findViewById(R.id.dakaijiao);
        textView3=findViewById(R.id.bihejiao);
        textView4=findViewById(R.id.duzhichi);
        textView5=findViewById(R.id.yucelabel);
        textView6=findViewById(R.id.yucescore);

        if(displayFea.length==4) {
            textView1.setText("对指角速度均方根：" + String.format(Locale.US, "%.2e", displayFea[0]).toString() + "rad/s");
            textView2.setText("打开角速度均方根：" + String.format(Locale.US, "%.2e", displayFea[1]).toString() + "rad/s");
            textView3.setText("闭合角速度均方根：" + String.format(Locale.US, "%.2e", displayFea[2]).toString() + "rad/s");
            textView4.setText("完成对指次数：" + String.valueOf(displayFea[3])+ "次");
            textView5.setText("预测的标签：" +utils.duizhiLabelChange(predictLabel));
            textView6.setText("预测评分：" + predictScore.toString());
        }else{
            Toast.makeText(DuizhiResActivity.this,"结果有错误，请重试",Toast.LENGTH_SHORT).show();
        }


    }
    // 处理返回箭头点击事件
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish(); // 结束当前Activity，返回上一个
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}